<template>
	<view>
		<view class="contain">
			<!-- 轮播区域 -->
			<view class="swip">
					<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
						<swiper-item v-for="(item,index) in bannerlist" :key="index">
							<view class="swiper-item">
								<image style="width: 100%;" :src="base+item.advImg" mode=""></image>
							</view>
						</swiper-item>
					</swiper>
			</view>
			<!-- 轮播end -->
			<!-- 宫格图 -->
			<view class="gong">
				<view class="gongbox" v-for="(item,index) in gong.slice(0,10)" :key="index" @click="tiao(index)">
					<image :src="'http://124.93.196.45:10001/'+item.imgUrl" style="width: 100rpx;" mode="widthFix"></image>
					<view class="">
						{{item.serviceName}}
					</view>
				</view>
			</view>
			<!-- 宫格图end -->
			<!-- 热门主题 -->
			<view class="hot">
				<view class="hotbox" v-for="(item,index) in advlist" :key="index">
					<image :src="base+item.advImg" style="width: 100%;border-top-left-radius: 10px;border-top-right-radius: 10px;" mode="widthFix"></image>
					<view><h4>{{item.advTitle}}</h4></view>
				</view>
			</view>
			<!-- 热门主题end -->
			<!-- 新闻标题栏 -->
			<view class="scroll" >
			</view>
			<scroll-view scroll-x="true" style="" :scroll-left="scrollL"  scroll-with-animation="true">
				<view style="display: flex;width: 130%; justify-content: space-around;">
					<view :class="[index==tagbox?'fouctag':'',]" v-for="(item,index) in news" :key="index" @click="toggle(item.id,index)">
						{{item.name}}
					</view>
				</view>
			</scroll-view>
			<!-- <view class="tag">
			</view> -->
			<!-- 新闻列表 -->
			<view class="newslist">
				<uni-list  :border="true">
						<!-- 显示圆形头像 -->
						<view class="" v-for="(item,index) in newslist.slice(0,5)" :key="index">
							<uni-list-chat :avatar-circle="true" :title="item.title" :avatar="base+item.cover" v-html=""  :note="item.content.replace(/<[^>]+>/g,'')" :time="item.commentDate" ></uni-list-chat>
						</view>
				</uni-list>
			</view>
		</view>
	</view>
</template>

<script>
	import {request,baseURL} from '../../utils/request.js'
	import {getnewslist,getadvlist} from "@/utils/index/index.js"
	export default {
		data() {
			return {
				scrollL:1,
				tagbox:0,
				bannerlist:[],
				gong:[],
				news:[],
				newslist:[],
				base:"",
				advlist:[]
			}
		},
		onLoad() {
			this.base=baseURL
			this.getbanner(),
			this.getgong(),
			this.getnews(),
			this.getnewslis(9)
			this.getadvlis()
		},
		methods: {
			async getadvlis(){
				const res=await getadvlist()
				this.advlist=res.data.rows
				console.log(res)
			},
			async getnewslis(type){
				console.log(type)
							const res=await getnewslist(type)
							console.log(res)
							this.newslist=res.data.rows
						},
		// async getnewslist(){
		// 	const res = await request({url:"/prod-api/press/comments/list",methods:'get',data:{id:1}})
		// 	this.newslist=res.data.rows
		// 	console.log(this.newslist)
		// },
			// 获取新闻
		async getnews(){
				const res=await request({url:"/prod-api/press/category/list",methods:"get"})
				console.log(res)
				this.news=res.data.data
		},
			// 获取轮播图
		async getbanner(){
				const res=await request({url:"/prod-api/api/rotation/list?type=2",methods:"get"})
				this.bannerlist=res.data.rows
				console.log(this.bannerlist)
			},
		async getgong(){
			const res = await request({url:"/prod-api/api/service/list",methods:"get"})
			// console.log(res)
			this.gong=res.data.rows
			this.gong[9]={serviceName:"更多服务",imgUrl:"/prod-api/profile/upload/image/2021/05/10/7abdfdc9-de48-4639-97a4-0cf2738a3073.png"}
		},
			// 跳转对应页面
			tiao(index){
				console.log(index)
				switch(index){
					case 5:uni.navigateTo({
						url:"/pages/car/car",
					})
					break;
					case 2:uni.navigateTo({
						url:"/pages/book/book"
					})
					break;
					case 6:uni.navigateTo({
						url:"/pages/subway/subway"
					})
					break;
					case 7:uni.navigateTo({
						url:"/pages/bus/bus"
					})
					break;
					default:break;
				}
			},
			toggle(e,index){
				console.log("-----------------")
				console.log(e)
				if(index==3){
					this.scrollL=e*100
					console.log(this.scrollL)
				}
				if(index==2){
					this.scrollL=-e*100
				}
					this.tagbox=index,
					this.getnewslis(e)
			
		}
	},
	}
</script>

<style>
	.scroll{
		width: 150%;
		display: flex;
		overflow-x: scroll;
		
	}
	.scroll>view{
		width: 25%;
		font-size: 32rpx;
	}
	.fouctag{
		font-weight: 700;
		border-bottom: 1px skyblue solid;
	}
	.tagbox{
		font-size: 32rpx;
		margin: 10px 10rpx;
	}
	.tag{
		display: flex;
		margin: 10px 10px;
	}
	.hotbox{
		width: 48%;
		text-align: center;
	}
	.gongbox{
		width: 19%;
		text-align: center;
	}
	.gong,.hot{
		margin: 50rpx 0px;
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}
	.swip{
		/* margin-top: 10px; */
		margin: 10px auto;
	}
	.contain{
		width: 94%;
		margin: 10px auto;
	}

</style>
